home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / memchr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  713 b   |  44 lines

  1. #include "lib.h"
  2.  
  3. /*
  4.  * memchr - search for a byte
  5.  *
  6.  * CHARBITS should be defined only if the compiler lacks "unsigned char".
  7.  * It should be a mask, e.g. 0377 for an 8-bit machine.
  8.  */
  9.  
  10. #ifdef NULL
  11. #undef NULL
  12. #endif
  13.  
  14. #define    NULL    0
  15.  
  16. #ifndef CHARBITS
  17. #    define    UNSCHAR(c)    ((unsigned char)(c))
  18. #    define  uchar        unsigned char
  19. #else
  20. #    define    UNSCHAR(c)    ((c)&CHARBITS)
  21. #    define  uchar        char
  22. #endif
  23.  
  24. _VOIDSTAR
  25. memchr(s, ucharwanted, size)
  26. _CONST _VOIDSTAR s;
  27. int ucharwanted;
  28. _SIZET size;
  29. {
  30.     register _CONST uchar *scan;
  31.     register _SIZET n;
  32.     register int uc;
  33.  
  34.     scan = s;
  35.     uc = UNSCHAR(ucharwanted);
  36.     for (n = size; n > 0; n--)
  37.         if (UNSCHAR(*scan) == uc)
  38.             return((char *)scan);
  39.         else
  40.             scan++;
  41.  
  42.     return(NULL);
  43. }
  44.